<template>
  <div class="step5">
    <el-form :rules="FormRules" ref="dataForm" :model="Form" label-width="300px" v-loading="listLoading">
      <el-form-item>
        <div class="tit" :style="{marginLeft:'-300px'}">
          <span>验证记录</span>
        </div>
      </el-form-item>
      <el-row>
        <el-col :span="16">
          <el-form-item label="选择报告模板：" prop="reportmodel">
            <el-select v-model="Form.reportmodel" placeholder="选择报告模板" :disabled="checkPermission(['engineer'])? false : true">
              <el-option v-for="item in reportModelOptions" :key="item.name" :label="item.name" :value="item.rid"></el-option>
            </el-select>
          </el-form-item>
           <el-form-item label="测试时间：" prop="acttesttime">
            <el-input v-model="Form.acttesttime" placeholder="请输入测试时间" :style="{width:'220px'}" :disabled="checkPermission(['engineer'])? false : true"/>
          </el-form-item>
          <el-form-item label="验证设备编号：" prop="devicecode">
            <el-input v-model="Form.devicecode" placeholder="请输入验证设备编号" :style="{width:'220px'}" :disabled="checkPermission(['engineer'])? false : true"/>
          </el-form-item>
          <el-form-item label="确认对象各项参数时间：" prop="confirmdate">
            <el-date-picker type="datetime" placeholder="请选择时间" v-model="Form.confirmdate" :disabled="checkPermission(['engineer'])? false : true"/>
          </el-form-item>
          <el-form-item label="确认并记录温控设备设置的温度范围时间：" prop="recorddate">
            <el-date-picker type="datetime" placeholder="请选择时间" v-model="Form.recorddate" :disabled="checkPermission(['engineer'])? false : true"/>
          </el-form-item>
          <el-form-item label="依照要求安装测点时间：" prop="installdate" >
            <el-date-picker type="datetime" placeholder="请选择时间" v-model="Form.installdate" :disabled="checkPermission(['engineer'])? false : true"/>
          </el-form-item>
          <el-form-item label="确认验证测点安装位置合理并拍照时间：" prop="takephotodate" >
            <el-date-picker type="datetime" placeholder="请选择时间" v-model="Form.takephotodate" :disabled="checkPermission(['engineer'])? false : true"/>
          </el-form-item>
          <el-form-item label="关闭车厢门验证开始时间："  prop="closedate">
            <el-date-picker type="datetime" placeholder="请选择时间" v-model="Form.closedate" :disabled="checkPermission(['engineer'])? false : true"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <div class="imgbox">
            <img v-preview="type1Img" :src="type1Img" preview-nav-enable="true" preview-title-enable="true">
            <p>现场操作记录表单</p>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <el-form :rules="FormRules" ref="dataForm" :model="Form" label-width="200px" v-loading="listLoading">
      <el-form-item>
        <div class="tit">
          <span>实际验证测点分布对应测点编号及位置关系</span>
        </div>
      </el-form-item>
      <el-row>
        <el-col :span="12">
          <div class="imgbox1" style="float:right">
            <div class="img">
              <img v-preview="type2Img" :src="type2Img" preview-nav-enable="true" preview-title-enable="true">
            </div>
            <div class="title">实际验证测点分布图</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="imgbox1">
            <div class="img">
              <img v-preview="type3Img" :src="type3Img" preview-nav-enable="true" preview-title-enable="true">
            </div>
            <div class="title">现场验证布点草图</div>
          </div>
        </el-col>
      </el-row>
      <div class="tip">注：传感器编号需与上传文件一致</div>
      <el-row>
        <el-col :span="8" v-for="(item,index) in Form.level" :key="index" v-loading = "codeLoading">
          <el-form-item :label="`标号${item.code}测点位置对应编号`" :prop="`level.${index}.sensorCode`" :rules="FormRules.levelNo">
            <el-input :style="{width:'110px'}" v-model="item.sensorCode" :placeholder="item.name" :disabled="checkPermission(['engineer'])? false : true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="10" :offset="2">
           <el-button type="primary" @click="UpdateDistribution">保存与分析</el-button>
        </el-col>
        <el-col :span="12">
          <el-form-item label="原测点位：" prop="codeid">
            <el-select v-model="Form.codeid" placeholder="选择原测点位" :disabled="checkPermission(['engineer'])? false : true">
              <el-option v-for="(item,index) in codeOptions" :key="index" :label="item" :value="index"></el-option>
            </el-select>
          </el-form-item>
         
        </el-col>
      </el-row>
      <el-form-item>
        <div class="tit">
          <span>稳态测试结果分析</span>
        </div>
      </el-form-item>
      <div class="tabtitle">稳态测试各测点温度数据统计表</div>
      <el-table ref="fullAnalysisTable" :data="fullAnalysisTable" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55">
          <template slot-scope="scope">
             <!-- 添加一个多选框,控制选中与否 -->
            <el-checkbox v-model="scope.row.isEnable == 1 ? true :false"  @change="handleChecked(scope.row)"></el-checkbox>
          </template>

        </el-table-column>
        <el-table-column prop="sensorCode" label="测点编号" width="120">
        </el-table-column>
        <el-table-column prop="min" label="最低温度(℃)" >
        </el-table-column>
        <el-table-column prop="max" label="最高温度(℃)" >
        </el-table-column>
        <el-table-column prop="avg" label="平均温度(℃)" >
        </el-table-column>
        <el-table-column prop="del" label="平均差值(℃)" >
        </el-table-column>
        <el-table-column prop="location" label="位置">
        </el-table-column>
      </el-table>

      <div class="result" v-if="fullAnalysisResult.avgmaxrecord.sensorCode != ''">
        <div class="title">稳态测试统计结论</div>
        <p>均值最热感受器编号为<span>{{fullAnalysisResult.avgmaxrecord.sensorCode }}</span>号，最热均值为<span>{{fullAnalysisResult.avgmaxrecord.temperature }}</span>℃；均值最冷感受器编号为<span>{{fullAnalysisResult.avgminrecord.sensorCode }}</span>号，最冷均值为<span>{{fullAnalysisResult.avgminrecord.temperature }}</span>℃。</p>
        <p>最冷感受器编号为<span>{{fullAnalysisResult.minminrecord.sensorCode }}</span>号，最低温度为<span>{{fullAnalysisResult.minminrecord.temperature }}</span>℃；最热感受器编号为<span>{{fullAnalysisResult.maxmaxrecord.sensorCode }}</span>号，最高温度为<span>{{fullAnalysisResult.maxmaxrecord.temperature }}</span>℃。</p>
        <p>最大温差感受器编号为<span>{{fullAnalysisResult.delmaxrecord.sensorCode }}</span>号，最大温差为<span>{{fullAnalysisResult.delmaxrecord.temperature }}</span>℃；最小温差感受器编号为<span>{{fullAnalysisResult.delminrecord.sensorCode }}</span>号，最小温差为<span>{{fullAnalysisResult.delminrecord.temperature }}</span>℃。</p>
        <p>各验证测点最低温度的总平均值为<span>{{fullAnalysisResult.min.avg }}</span>℃，表明制冷机实际停止的温度低点与设定的温度低点有<span>{{fullAnalysisResult.min.del }}</span>℃的偏差；</p>
        <p>各验证测点最高温度的总平均值为<span>{{fullAnalysisResult.max.avg }}</span>℃，表明制冷机实际启动的温度高点与设定的温度高点有<span>{{fullAnalysisResult.max.del }}</span>℃的偏差；</p>
        <p>各验证测点温度的总平均值为<span>{{fullAnalysisResult.average.avg }}</span>℃；</p>
        <p>各验证测点温度的平均差值为<span>{{fullAnalysisResult.average.del }}</span>℃。</p>
      </div>

      <div class="tabtitle">排除测点后稳态测试各测点温度数据统计表</div>
      <el-table :data="enableAnalysisTable" tooltip-effect="dark" style="width: 100%" >
         <el-table-column prop="sensorCode" label="测点编号" width="120">
        </el-table-column>
        <el-table-column prop="min" label="最低温度(℃)" >
        </el-table-column>
        <el-table-column prop="max" label="最高温度(℃)" >
        </el-table-column>
        <el-table-column prop="avg" label="平均温度(℃)" >
        </el-table-column>
        <el-table-column prop="del" label="平均差值(℃)" >
        </el-table-column>
        <el-table-column prop="location" label="位置">
        </el-table-column>
      </el-table>
       <div class="result" v-if="enableAnalysisResult.avgmaxrecord.sensorCode != ''">
        <div class="title">排除测点后稳态测试统计结论</div>
        <p>均值最热感受器编号为<span>{{enableAnalysisResult.avgmaxrecord.sensorCode }}</span>号，最热均值为<span>{{enableAnalysisResult.avgmaxrecord.temperature }}</span>℃；均值最冷感受器编号为<span>{{enableAnalysisResult.avgminrecord.sensorCode }}</span>号，最冷均值为<span>{{fullAnalysisResult.avgminrecord.temperature }}</span>℃。</p>
        <p>最冷感受器编号为<span>{{enableAnalysisResult.minminrecord.sensorCode }}</span>号，最低温度为<span>{{enableAnalysisResult.minminrecord.temperature }}</span>℃；最热感受器编号为<span>{{enableAnalysisResult.maxmaxrecord.sensorCode }}</span>号，最高温度为<span>{{fullAnalysisResult.maxmaxrecord.temperature }}</span>℃。</p>
        <p>最大温差感受器编号为<span>{{enableAnalysisResult.delmaxrecord.sensorCode }}</span>号，最大温差为<span>{{enableAnalysisResult.delmaxrecord.temperature }}</span>℃；最小温差感受器编号为<span>{{enableAnalysisResult.delminrecord.sensorCode }}</span>号，最小温差为<span>{{fullAnalysisResult.delminrecord.temperature }}</span>℃。</p>
        <p>各验证测点最低温度的总平均值为<span>{{enableAnalysisResult.min.avg }}</span>℃，表明制冷机实际停止的温度低点与设定的温度低点有<span>{{enableAnalysisResult.min.del }}</span>℃的偏差；</p>
        <p>各验证测点最高温度的总平均值为<span>{{enableAnalysisResult.max.avg }}</span>℃，表明制冷机实际启动的温度高点与设定的温度高点有<span>{{enableAnalysisResult.max.del }}</span>℃的偏差；</p>
        <p>各验证测点温度的总平均值为<span>{{enableAnalysisResult.average.avg }}</span>℃；</p>
        <p>各验证测点温度的平均差值为<span>{{enableAnalysisResult.average.del }}</span>℃。</p>
      </div>
      
      <el-form-item label="选择点：" prop="type">
      <el-radio-group v-model="Form.choosecodeid" >
        <el-radio :label="1">极值最热点<span>{{enableAnalysisResult.maxmaxrecord.sensorCode }}</span>号</el-radio>
        <el-radio :label="2">极值最冷点<span>{{enableAnalysisResult.minminrecord.sensorCode }}</span>号</el-radio>
        <el-radio :label="3">均值最热点<span>{{enableAnalysisResult.avgmaxrecord.sensorCode }}</span>号</el-radio>
        <el-radio :label="4">均值最冷点<span>{{enableAnalysisResult.avgminrecord.sensorCode }}</span>号</el-radio>
      </el-radio-group>
    </el-form-item>
      <el-form-item label="推荐日常中心点安装位置：" prop="recommendpic">
      <UploadImg ref="createUploadImg" :imgName="imgName" :FileUrl="imgUploadUrl" :isMultiple="false" :isAutoUpload="false" :Data="Data" :handleChange="handleChange" ></UploadImg>
      </el-form-item>

      <el-form-item label="验证中心点温度设定值：" prop="centertemperature">
        <el-input-number v-model="Form.centertemperature" :precision="2" :step="0.1"  :disabled="checkPermission(['engineer'])? false : true"/>&nbsp;℃
      </el-form-item>
      <el-form-item label="药品合理存放区域：" prop="storageareapic">
        <el-select v-model="Form.storageareapic" placeholder="选择图片模板" @change="storageareapicChange" :disabled="checkPermission(['engineer'])? false : true">
          <el-option v-for="item in picModelOptions" :key="item.picModel" :label="item.name" :value="item.picModel"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <img :src="storageareapic" width="250">
        <img v-if="storageareapic==''" :src="defaultImg" width="250">
      </el-form-item>

      <el-form-item>
        <el-button  :disabled="checkPermission(['engineer'])? false : true" v-if="saveShow" @click="saveForm('dataForm')">保存</el-button>
        <el-button type="primary" :disabled="checkPermission(['engineer'])? false : true" @click="submitForm('dataForm')">提交</el-button>
        <el-button type="warning" @click="generateForm('dataForm')" :loading="exportLoading || countLoading" >{{exportButton}}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import checkPermission from "@/utils/permission"; // 权限判断函数
import UploadImg from '@/components/Upload/UploadImg'
import {
  getProjectContentPic,
  getProjectContentInfo,
  projectContentTruckUpdate,
  getDistributionInfo,
  DistributionUpdate,
  projectContentAnalysis,
  updateProjectSensorPosition
} from "@/api/projectContent";
import { getTaskData } from "@/api/task";
import { getPicModelList } from "@/api/pictureModel";
import { getTextModelList } from "@/api/textModel";
import { getPlanModelPic } from "@/api/projectContent";
import { getReportList } from "@/api/report";
import {  getProjectData, generateReport, getGenerateStatus, getGenerateFile, resetGenerateStatus,  updateProjectState} from "@/api/project";
const defaultAnalysisResult = {
  minminrecord:{
    sensorCode:'',
    temperature:''
  },
  average:{
    avg:'',
    del:''
  },
  min:{
    avg:'',
    del:''
  },
  max:{
    avg:'',
    del:''
  },
  delminrecord:{
    sensorCode:'',
    temperature:''
  },
  avgminrecord:{
    sensorCode:'',
    temperature:''
  },
  delmaxrecord:{
    sensorCode:'',
    temperature:''
  },
  avgmaxrecord:{
    sensorCode:'',
    temperature:''
  },
  maxmaxrecord:{
    sensorCode:'',
    temperature:''
  }
};
export default {
  name: "carStep5",
  props: ["getId"],
  components: {UploadImg },
  data() {
    return {
      imgName:'',
      imgUploadUrl:'',
      Data:{},
      defaultImg: require("@/assets/noimg.jpg"),
      listLoading: false,
      codeLoading: false,
      exportstatus: 0,
      countLoading: false,
      exportButton: "生成报告",
      saveShow: true,
      textModelOptions: [],
      reportModelOptions: [],
      codeOptions:[],
      picModelOptions: [],
      fullAnalysisTable:[],
      fullAnalysisResult:{},
      enableAnalysisTable:[],
      enableAnalysisResult:{},
      arrangementpic: "",
      storageareapic: "",
      type1Img: "",
      type2Img: "",
      type3Img: "",
      customerId: null,
      Form: {
        level: [],
        reportmodel: null, // 报告模板
        acttesttime: "",  // 测试时间
        devicecode: "", // 验证设备编号
        confirmdate: new Date(), // 确认验证对象各项参数时间
        recorddate:new Date(), // 确认并记录温控设备设置的温度范围时间
        installdate: new Date(), // 依照要求安装测点时间
        takephotodate:new Date(), //确认验证测点安装位置合理并拍照时间
        closedate: new Date(), // 关闭车厢门验证开始时间
        centertemperature:0,  //验证中心点温度设定值
        codeid:null, //原测点位
        choosecodeid:1,//选择测点位
        recommendpic:'',  //推荐日常监测点安装位置
        storageareapic: null, // 药品合理存放区域图
      },
      FormRules: {
        reportmodel: [ { required: true, message: "请选择报告模板", trigger: "change" } ],
        levelNo: [ { required: true, message: "请填写位置对应编号", trigger: "blur" } ],
        acttesttime: [ { required: true, message: "请填写测试时间", trigger: "blur" } ],
        devicecode: [ { required: true, message: "请填写验证设备编号", trigger: "blur" }],
        confirmdate: [ { type: "date", required: true, message: "请填写确认验证对象各项参数时间", trigger: "change" } ],
        installdate: [ { type: "date", required: true, message: "请填写依据要求安装验证测点时间", trigger: "change" } ],
        takephotodate: [ { type: "date", required: true, message: "请填写确认验证测点安装位置合理并拍照时间", trigger: "change" } ],
        closedate: [ { type: "date", required: true, message: "请填写关闭车厢门验证开始时间", trigger: "change" }],
        recommendpic:[ { required: true, message: "请上传推荐日常监测点安装位置图", trigger: "change" }],
        storageareapic: [ { required: true, message: "请选择药品合理存放区域图片", trigger: "change" } ]
      }
    };
  },
  computed: {
    exportLoading() {
      if (this.exportstatus == 1) {
        this.exportButton = "生成中，请稍候";
        return true;
      } else {
        this.exportButton = "生成报告";
        return false;
      }
    }
  },
  methods: {
    checkPermission,
    // 药品合理存放区域
    storageareapicChange(val) {
      for (var picdata of this.picModelOptions) {
        if (val == picdata.picModel) {
          this.storageareapic = picdata.imgUrl;
        }
      }
    },
    // 上传图片
   handleChange(file, fileList){
     console.log(file)
    const isImage = file.raw.type == "image/png" || file.raw.type == "image/jpg" || file.raw.type == "image/jpeg";
      if (!isImage) {
        this.$message.error("上传图片只能是JPG或者png格式!");
        fileList.pop();
      }else{
        this.Form.recommendpic = file;
        this.imgName = file.url;
        console.log(this.imgName)
      }
      return isImage;
   },

   handleSelectionChange(val){
    //  this.enableAnalysisTable = val
   },

    //获取图片
    getImg() {
      getProjectContentPic({ projectId: this.getId, typeId: 1 })
        .then(response => {
          if (response.data == null) {
            this.type1Img = this.defaultImg;
          } else {
            this.type1Img = response.data.url;
          }
        })
        .catch(e => {
          console.log(e);
        });
      getPlanModelPic({ projectId: this.getId })
        .then(response => {
          if (response.data == null || response.data == "") {
            this.type2Img = this.defaultImg;
          } else {
            this.type2Img = response.data;
          }
        })
        .catch(e => {
          console.log(e);
        });
      getProjectContentPic({ projectId: this.getId, typeId: 2 })
        .then(response => {
          if (response.data == null) {
            this.type3Img = this.defaultImg;
          } else {
            this.type3Img = response.data.url;
          }
        })
        .catch(e => {
          console.log(e);
        });
    },

    //获取文字和图片模板列表
    getModel() {
      this.listLoading = true;
      //获取主项目customerId
      getProjectData({ projectId: this.getId }).then(res => {
        getTaskData({ taskId: res.data.tid })
          .then(response => {
            this.customerId = response.data.customerId;
            //获取报告模板
            getReportList({ customerId: this.customerId, deviceType: 2 })
              .then(response => {
                this.reportModelOptions = response.data;
              })
              .catch(e => {
                console.log(e);
              });
            //获取文字模板
            getTextModelList({ customerId: this.customerId, deviceType: 2 })
              .then(response => {
                this.textModelOptions = response.data.map(item => {
                  return {
                    textModel: item.id,
                    name: item.name,
                    content: item.content
                  };
                });
              })
              .catch(e => {
                console.log(e);
              });
            //获取图片模板
            getPicModelList({ customerId: this.customerId, deviceType: 2 })
              .then(response => {
                this.picModelOptions = response.data.map(item => {
                  return {
                    picModel: item.id,
                    name: item.name,
                    imgUrl: item.url
                  };
                });
                this.getProjectContent();
                this.listLoading = false;
              })
              .catch(e => {
                console.log(e);
              });
          })
          .catch(e => {
            console.log(e);
          });
      });
    },

    //获取布点信息
    getDistribution() {
      this.codeLoading = true;
      getDistributionInfo({ projectId: this.getId })
        .then(response => {
          this.Form.level = response.data;
          this.codeOptions = []
          response.data.forEach(element => {
            this.codeOptions.push(element.sensorCode)
          });
          this.codeLoading = false;
        })
        .catch(e => {});
    },

    //获取分析结果
    getAnalysis(){
      projectContentAnalysis({projectId: 14,}).then(res=>{
        this.fullAnalysisTable  = res.data.fullanalysistable
        this.enableAnalysisTable = res.data.enableanalysistable
        res.data.fullanalysisresult == {} ? this.fullAnalysisResult = Object.assign({}, defaultAnalysisResult):this.fullAnalysisResult = res.data.fullanalysisresult
        res.data.enableanalysisresult == {} ? this.enableAnalysisResult = Object.assign({}, defaultAnalysisResult):this.enableAnalysisResult = res.data.enableanalysisresult
      }).catch(e=>{e})
    },

    // 切换分析表格选中状态
    handleChecked(row) {
      let projectSensorPosition = {
        projectId:14,
        sensorCode:row.sensorCode,
        isEnable:Number(row.isEnable)
      }
      if(projectSensorPosition.isEnable == 0){
        projectSensorPosition.isEnable = 1
        updateProjectSensorPosition(projectSensorPosition).then(()=>{
          this.getAnalysis()
        })
      } else {
        projectSensorPosition.isEnable = 0
          updateProjectSensorPosition(projectSensorPosition).then(()=>{
           this.getAnalysis()
          })
        } 
      
    },

    //获取冷藏车验证内容信息
    getProjectContent() {
      getProjectContentInfo({ projectId: this.getId }).then(response => {
        console.log(response)
        for (const item of response.data) {
          this.Form[item.name] = item.genre == "point" || item.genre == "int" ? Number(item.value) : item.value;
          this.$nextTick(() => {
            const keyMap = [
              {
                key: "storageareapic",
                value: "storageareapic"
              }
            ];
            for (const item of keyMap) {
              const { key, value } = item;
              for (const picdata of this.picModelOptions) {
                const { picModel, imgUrl } = picdata;
                if (this.Form[key] === picModel) {
                  this[value] = imgUrl;
                }
              }
            }
          });
        }
      });
    },

    //布点信息提交
    UpdateDistribution() {
      //布点信息更新
      let list = [];
      list = this.Form.level.map(item => {
        if (item.id == null) {
          //  新建位置布点关系 没有id
          return {
            positionId: item.pid,
            projectId: this.getId,
            sensorCode: item.sensorCode
          };
        } else {
          //  更新位置布点关系
          return {
            id: item.id,
            positionId: item.pid,
            projectId: this.getId,
            sensorCode: Number(item.sensorCode)
          };
        }
      });
      DistributionUpdate({ list }).then(() => {
          this.getDistribution();
          this.getAnalysis();
        }).catch(e => {
          console.log("布点信息提交失败", e);
        });
    },

    submitFormData(){
      this.Form.confirmdate = new Date(this.Form.confirmdate);
      this.Form.installdate = new Date(this.Form.installdate);
      this.Form.closedate = new Date(this.Form.closedate);
      this.Form.recorddate = new Date(this.Form.confirmdate);
      this.Form.takephotodate = new Date(this.Form.installdate); 
    },

    //保存--表格不做验证
    saveForm() {
      this.listLoading = true;
      this.submitFormData();
      let list1 = [];
      //将form对象转成数组
      for (let key of Object.keys(this.Form)) {
        if (key != "level")
          list1.push({
            projectId: this.getId,
            name: key,
            value: this.Form[key]
          });
      }
      projectContentTruckUpdate({ list: list1 })
        .then(response => {
          this.getModel();
          this.listLoading = false;
          this.$notify({
            title: "成功",
            message: "保存成功",
            type: "success",
            duration: 2000
          });
        })
        .catch(e => {
          console.log("验证内容表单提交失败", e);
        });
    },

    //提交--表格做验证
    submitForm(formName) {
      this.Form.confirmdate = new Date(this.Form.confirmdate);
      this.Form.installdate = new Date(this.Form.installdate);
      this.Form.closedate = new Date(this.Form.closedate);
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$confirm("确认提交吗？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消"
          }).then(() => {
            this.listLoading = true;
            let list1 = [];
            //将form对象转成数组
            for (const key of Object.keys(this.Form)) {
              if (key != "level")
                list1.push({
                  projectId: this.getId,
                  name: key,
                  value: this.Form[key]
                });
            }
            projectContentTruckUpdate({ list: list1 })
              .then(response => {
                //布点信息更新
                this.getModel();
                this.listLoading = false;
                this.$notify({
                  title: "成功",
                  message: "表单提交成功",
                  type: "success",
                  duration: 2000
                });
                updateProjectState({ pid: this.getId, state: 2 }).then(_ => {
                  this.$emit("changeState");
                });
              })
              .catch(e => {
                console.log(e);
              });
            this.saveShow = false;
          }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消提交'
          });
        });;
        }
      });
    },

    // 获取报告生成状态 res.data 0,暂时无法导出 1，生成中 2，生成完成
    getExportStatus() {
      getGenerateStatus({ projectId: this.getId })
        .then(res => {
          let originexportstatus = this.exportstatus;
          this.exportstatus = res.data;
          if (originexportstatus != 2 && this.exportstatus == 2) {
            getGenerateFile({ projectId: this.getId })
              .then(response => {
                this.$confirm(`生成成功,立刻下载`, "提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消"
                })
                  .then(() => {
                    window.open(response.data);
                    this.$message({
                      type: "success",
                      message: "下载成功"
                    });
                    resetGenerateStatus({ projectId: this.getId });
                  })
                  .catch(() => {
                    resetGenerateStatus({ projectId: this.getId });
                    this.$message({
                      type: "info",
                      message: "已取消下载"
                    });
                  });
              })
              .catch(e => {
                console.log(e);
              });
          }
        })
        .catch(e => {
          console.log(e);
        });
    },

    //生成--表格做验证
    generateForm(formName) {
      this.Form.confirmdate = new Date(this.Form.confirmdate);
      this.Form.installdate = new Date(this.Form.installdate);
      this.Form.closedate = new Date(this.Form.closedate);
      this.$refs[formName].validate(valid => {
        this.listLoading = true;
        let list1 = [];
        //将form对象转成数组
        for (const key of Object.keys(this.Form)) {
          if (key != "level")
            list1.push({
              projectId: this.getId,
              name: key,
              value: this.Form[key]
            });
        }
        projectContentTruckUpdate({ list: list1 })
          .then(response => {
            this.getModel();
            this.listLoading = false;
            let _this = this;
            _this.$nextTick(() => {
              _this.$confirm("确认生成报告吗？", "提示", {
                  type: "warning"
                })
                .then(() => {
                  this.countLoading = true;
                  generateReport({ projectId: _this.getId })
                    .then(response => {
                      this.countLoading = false;
                      this.exportstatus = 1;
                      this.exportButton = "生成中，请稍侯";
                    })
                    .catch(e => {
                      console.log(e);
                    });
                });
            });
          })
          .catch(e => {
            console.log(e);
          });
      });
    }
  },

  created() {
    let _this = this;
    _this.fullAnalysisResult = Object.assign({}, defaultAnalysisResult);
    _this.enableAnalysisResult = Object.assign({}, defaultAnalysisResult);
    _this.getImg();
    _this.getDistribution();
    _this.getAnalysis();
    _this.getModel();
    // _this.interval = setInterval(function() {
    //   _this.getExportStatus();
    // }, 3000);
  },
  destroyed() {
    clearInterval(this.interval);
  }
};
</script>
<style lang="scss" scoped>
.step5 {
  .tit {
    border-bottom: 1px solid #ebeef5;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    margin-left: -200px;
    font-weight: 700;
  }
  .imgbox {
    width: 250px;
    text-align: center;
    line-height: 30px;
    box-shadow: 0 6px 18px 0 rgba(232, 237, 250, 0.5);
    img {
      width: 100%;
      border: 1px solid #eee;
      cursor: pointer;
    }
  }
  .imgbox1 {
    float: left;
    width: 200px;
    height: 230px;
    margin-left: 20px;
    margin-bottom: 20px;
    text-align: center;
    box-shadow: 0 6px 18px 0 rgba(232, 237, 250, 0.5);
    .img {
      border: 1px solid #eee;
      width: 198px;
      height: 198px;
      overflow: hidden;
      cursor: pointer;
      img {
        width: 100%;
      }
    }
    .title {
      line-height: 30px;
      font-size: 14px;
    }
  }
  .labelWidth {
    width: 120px;
  }
}
.tip{
  font-size: 12px;
  text-align: center;
  padding: 20px;
}
.tabtitle{
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  padding: 20px;
}
.result{
  padding:20px 0;
  p{
    font-size: 14px;
    line-height:30px;
    span{
      font-weight: 700;
    }
  }
    
}
</style>



